Magnitude and Phase

mag(v) Returns a vector containing the magnitudes of the elements in the complex vector v.

makeri(magvec, phasevec) Returns a vector of complex numbers whose magnitudes and phases are contained in magvec and phasevec.

phase(v) Returns a vector containing the phases of the elements in the complex vector v.

phasecor(phasevec) Returns a vector generated from the vector of phases v by removing jump discontinuities.

Arguments:

v is a real or complex-valued vector or matrix.

phasevec is a real-valued vector or matrix of element-wise phases.

magvec is a real-valued vector or matrix of element-wise magnitudes. magvec has the same length as phasevec.

Note:

  • Ambiguity in angle selection can cause the phase of the output vector to differ from the phase of the input vector. The two vectors will agree up to multiples of 2p.

  • If an element in magvec is negative, its absolute value is interpreted as the desired magnitude, and the corresponding element in phasevec is advanced p radians.


Noise Generators

gaussn(n) Returns an n-element vector of noise following a Gaussian probability distribution of mean 0 and standard deviation 1.

onefn(n) Returns an n-element vector of 1/f noise.

whiten(n) Returns an n-element vector of uniformly distributed white noise.

Arguments:

n is an integer greater than or equal to 2.

Note:

  • The sequence of numbers is determined by a seed value, like Mathcad's built-in function rnd. Information on the seed value can be found in the Mathcad on-line help.


Quantizing a Signal

quantize(v, n) Returns a vector that assigns the elements of v to n equally-spaced levels.

Arguments:

v is a a real-valued vector or matrix.

n is a real number greater than or equal to 1.

Note:

  • Quantization levels are chosen so that the lowest and highest levels are the minimum and maximum values of v.


Convolution and Correlation

convol(vx, vy) Returns the convolution of the vectors vx and vy.

correl(vx, vy) Returns the correlation of the vectors vx and vy.

covar(vx, vy) Returns the covariance of the vectors vx and vy.

deconvol(vz, vx) Returns the deconvolution of the vector vz by the vector vx.

lcorr(vx, vy) Returns a vector giving the correlation of the vectors vx and vy at each possible lag.

Arguments:

vx and vy are real- or complex-valued vectors or matrices of at least two elements. For lcorr, vx and vy must be real-valued vectors.

vz is a real- or complex-valued vector of element such that:

length(vz) - length(vx) > 0.

Note:

  • The length of the results returned by convol, correl, and covar is [length(vx) + length(vy)] - 1.

  • The length of the result returned by deconv is [length(vz) - length(vx)]+1.

  • The length of the result returned by lcorr is the same as vx.

  • All functions make use of the FFT algorithm and zero-padding.


Two-Dimensional Correlation

correl2d(M, K) Returns the 2D correlation of matrices M and K.

Arguments:

M is the image matrix.

K is an arbitrary kernel, which should be smaller than the image M.

Note:

  • Correlation is performed in the spatial domain, and image boundaries are treated by zero padding the input image; however, the size of the output image is the same as the input image.

  • The origin of the kernel is assumed to be at the center of the kernel which ensures a zero-phase shift correlation output. (i.e. The corresponding features in the input and output images are not shifted with respect to each other.)


Signal Windowing

blackman(n) Returns a Blackman window of width n.

cheby(n, b) Returns a Chebyshev window of width n and parameter b.

costaper(n, a) Returns a cosine taper window of length n, with the percentage of raised cosine given by a.

gaussian(n, a) Returns a Gaussian window of width n; the parameter a controls the peak width.

hamming(n) Returns a Hamming window of width n.

hanning(n) Returns a Hanning window of width n.

kaiser(n, b) Returns a Kaiser window of width n and parameter b.

nuttall(n) Returns a Nuttall window of width n.

taprect(n) Returns a tapered rectangular window of width n.

triangular(n) Returns a triangular window of width n.

Arguments:

n is an integer of at least 2. For Chebychev windows, n must be odd.

a is the inverse of the Gaussian variance, a real number between 0 and 20, or, a is a percentage of tapered cosine in costaper, a real number between 0 and 1.

b for Kaiser windows is a real number such that 2 < b < 20. b is a Chebychev sidelobe ripple, a real number greater than 1, typically b>50.


Spectral Analysis

coherence(vx, vy, n, r, [w]) Returns the coherence of vectors vx and vy. The signal vectors are divided into n overlapping intervals with fraction of overlap r. Each data segment is windowed with taper w.

cspectrum(vx, vy, n, r, [w]) Returns the cross spectrum of the vectors vx and vy. The signal vectors are divided into n overlapping intervals with fraction of overlap r. Each data segment is windowed with taper w.

pspectrum(v, n, r, [w]) Returns the power spectrum of v, computed by dividing v into n overlapping segments with overlap fraction r. Each data segment is windowed with taper w.

snr(vx, vy, n, r, [w]) Returns the signal-to-noise ratio for vx and vy. The signal vectors are divided into n overlapping segments with fraction of overlap r. Each data segment is windowed with taper w.

Arguments:

v, vy, and vy are complex-valued signal vectors.

n is an integer between 1 and length(vx) representing the subdivisions of the input signal(s).

r is the percent overlap between subdivisions. 0 [image] r > 1.

w (optional) is an integer representing a windowing function. A rectangular window is used if w is omitted. The following table shows values for w and the windows they correspond to:

Value of w | Window
1 | rectangular
2 | tapered rectangular
3 | triangular
4 | Hanning
5 | Hamming
6 | Blackman


Cepstrum and Complex Cepstrum

cepstrum(v) Returns the cepstrum of the vector v.

ccepstrum(A) Returns a matrix containing the complex cepstrum of a multichannel signal A.

Arguments:

v is a real-valued vector.

A is a vector or matrix. If A is a matrix, the individual columns are acted upon.


Cyclic Permutation

recenter(A) Returns a recentered version of array A, cyclically permuted to bring the first element of A to the middle.

Arguments:

A is a real or complex-valued vector or matrix.


Chirp z-Transform

chirpz(v, lo, hi, d) Returns the frequency spectrum of the signal v between lo and hi at frequency intervals of d.

Arguments:

v is a real- or complex-valued array.

lo and hi are positive, real values for the endpoints of the frequency range. They are normalized so the sampling frequency is 1. hi is never greater than 0.5.

d is a positive real frequency step size, such that (hi - lo)/d is at least 2.

Note:

  • chirpz takes the FFT of an array with length of the original input signal plus the number of points in the interpolated spectrum minus one.

  • If the total length of the array delivered to the FFT is prime or has few factors, this calculation will be slow.


Filter Gain

gain(C, f) Returns the gain at frequency f of a filter with coefficients C.

Arguments:

C is a real or complex-valued vector or array of filter coefficients.

FIR filter: C has one column

IIR filter: C has column pairs: column 1 contains coefficients of the numerator, column 2 contains coefficients of the denominator. IIR transfer functions must be normalized so that the constant term in the denominator is 1.

f is a positive real number (or real-valued vector) between 0 and 1. It represents the frequency as a fraction of the sampling frequency. Frequency is generally be between 0 and .5.


Time Response of Digital Filters

fftfilt(v, C1, [nfft]) Returns a matrix with the result of the convolution of a multichannel signal v, with an array C, calculated by computing the FFT of length nfft.

response(v, C2, n) Returns a vector giving n terms of the response of an input vector v to an FIR or IIR filter with coefficient array C.

Arguments:

v is a real or complex-valued signal vector or multichannel matrix, filtered individually by column.

C1 is a real or complex-valued vector or matrix of FIR filter coefficients. C1 has one column

C2 is a real or complex-valued vector or matrix of FIR or IIR filter coefficients.

FIR filter: C2 has one column

IIR filter: C2 has column pairs: column 1 contains coefficients of the numerator, column 2 contains coefficients of the denominator. IIR transfer functions must be normalized so that the constant term in the denominator is 1.

n is a positive integer, the size of the output vector, no greater than the length of the input.

nfft (optional) is a positive integer, the length of the fft in the overlap-add method. It may not be greater than the length of the signal. If omitted, nfft is the length of the filter.

Notes:

  • If the final transient response is desired, zeropadded the input signal to the appropriate length, and then increase n.

  • For an IIR filter, response must always be used. For an FIR filter with an impulse response much shorter than the input signal, fftfilt may be used as an option, and often it will provide a faster result.


FIR Filter Design

bandpass(f1, f2, n, [w]) Returns coefficients for a bandpass FIR filter with n coefficients and cutoff frequencies f1 and f2, windowed with a taper w.

bandstop(f1, f2, n, [w]) Returns coefficients for a bandstop FIR filter with n coefficients and cutoff frequencies f1 and f2, windowed with taper w.

highpass(f, n, [w]) Returns coefficients for a highpass FIR filter with n coefficients and cutoff frequency f, windowed with taper w.

lowpass(f, n, [w]) Returns coefficients for a lowpass FIR filter with n coefficients and cutoff frequency f, windowed with taper w.

setwindow(n) Returns the currently selected window for FIR filter design using the functions lowpass, highpass, bandpass, and bandstop. The argument n sets the window to one of six available windows.

Arguments:

f, f1, and f2 are real-valued cutoff or bandpass frequencies, given as a fraction of the sampling frequency, between 0 and 0.5.

n is an integer greater than 2. It represents the number of coefficients for the filter

w (optional) is an integer representing a windowing function. A rectangular window is used if w is omitted. The following table shows values for w and the windows they correspond to:

Value of w | Window
1 | rectangular
2 | tapered rectangular
3 | triangular
4 | Hanning
5 | Hamming
6 | Blackman


FIR Filters by Remez Exchange

remez(vg, vr, vw, n) Returns coefficients for an FIR filter of length n generated by the Remez exchange algorithm.

Arguments:

g is a real vector, a grid of frequencies between 0 and .5.

r is a real vector of values between 0 and 1, the same length as g. Contains the frequency response over g.

w is a real vector of values between 0 and 1, the same length as g. Contains error weight over g.

n is an integer, the length of the filter. n is at least 8.

Note:

  • remez is sensitive to the chosen number of coefficients. Always check filter gain against the desired frequency response. If the match is poor, change n to a larger value until the desired response is achieved.


IRR Filter Coefficients

bessel(n, scale) Returns coefficients for an analog Bessel filter of order n; scale controls the gain at cutoff. The output is used as an argument to one of the IRR filter functions.

butter(n) Returns coefficients for an analog Butterworth filter of order n. The output is used as an argument to one of the IRR filter functions.

cheby1(n, e) Returns coefficients for a Type I Chebyshev analog filter of order n; ripple is controlled by the parameter e. The output is used as an argument to one of the IRR filter functions.

cheby2(n, scale, atten) Returns coefficients for a Type II Chebyshev analog filter of order n with the lower edge of the stopband at s and stopband attenuation atten. The output is an argument to the IRR filter functions.

Arguments:

n is an integer filter order. For bessel filters n is between 1 and 35. For all others, it is between 1 and 200.

e is a positive real number representing the allowable passband ripple.

scale for bessel is a real number greater than 0 which sets the lower edge of the stopband. scale for cheby2 is a calculated real number greater than 1 setting the lower edge of the stopband.

atten is a real number greater than 1, the stopband attenuation factor.

Note:

  • These functions produce coefficient arrays with an even number of columns. If there are two columns, as in the output of bessel, the filter consists of a single section: column 1 contains coefficients of the transfer function numerator, column 2 contains denominator coefficients. If there are more than two columns, each pair represents a section of a filter in cascade form.


IRR Filters

irrhigh(C, f) Returns coefficients for a highpass IIR filter with cutoff frequency f. The input array C is generated by one of the IIR filter coefficient functions.

irrlow(C, f) Returns coefficients for a lowpass IIR filter with cutoff frequency f. The input array C is generated by one of the IIR filter coefficient functions.

irrpass(C, lowf, highf) Returns coefficients for a bandpass IIR filter with cutoff frequencies lowf and highf. The input array C is generated by one of the IIR filter coefficient functions.

irrstop(C, lowf, highf) Returns coefficients for a bandstop IIR filter with cutoff frequencies lowf and highf. The input array C is generated by one of the IIR filter coefficient functions.

Arguments:

C is a coefficient array produced by one of the IIR filter coefficient functions.

f, lowf, and highf are real frequencies, normalized to the sampling frequency, between 0 and 0.5.


Interpolation and Resampling

interpolate(v, n) Returns an interpolated version of the vector v with n times as many points as v.

multirate(v, n, m, [f]) Returns a version of multichannel signal v resampled by a factor of n/m, using the optional argument f as the lowpass interpolating filter.

resample(v, m, n) Returns a vector obtained from v by n-fold interpolation and then sampling every mth point.

Arguments:

v is a vector or matrix of real or complex numbers representing the samples of a signal. If v is a matrix, each column is processed individually. For resample, data must be real.

n is an integer, the upsampling/interpolation factor. For resample and interpolate, n [image] 2.

m is an integer, downsampling/decimation factor. For resample, n [image] 2.

f, (optional) is a vector of FIR lowpass filter coefficients used between upsampling and downsampling. Default filter has length 32, gain n, windowed with a Hanning taper, with cutoff .45 times the min(1/n,1/m).


Smoothing

expsmooth(v, a) Returns a smoothed version of the data in vector v generated by exponential smoothing with weight a.

medfilt1d(M, n) Returns the multichannel signal M, filtered with a median filter of length n.

movavg(v, n) Returns a smoothed version of the data in vector v created by taking a moving average with a window of width n.

Arguments:

v is a complex-valued data vector or matrix.

M is a real-valued vector or matrix. If M is a matrix, filtering is applied column by column.

n is an integer, the moving average window width or median filter length.

a is the exponential window parameter, 0 [image] a [image] 1.


Linear Detrending

detrend(v) Returns the array v with any linear trend removed.

Arguments:

v is a real- or complex-valued data array whose length is greater than or equal to 3.


Linear Prediction Methods

burg(v, n) Returns coefficients for nth order linear prediction generated from the vector v using Burg's method.

yulew(v, n) Returns coefficients for nth order linear prediction generated from the vector v using the Yule-Walker algorithm.

Arguments:

v is a real-valued vector of data to be predicted.

n is an integer, the order of the model, where 1 < n < length(v).

Note:

  • To calculate predicted values, ignore the zeroth element of the output coefficient vector which is always 1.


Correlation and Partial Autocorrelation

lcorr(vx, vy) Returns a vector giving the correlation of the vectors vx and vy at each possible lag.

pcorr(v) Returns a vector giving the partial autocorrelation of the vector v at each lag.

Arguments:

vx and vy are real-valued vectors of the same length.

v is a real-valued vector.


Hartley Transform

dht(v) Returns the Hartley transform of the vector v.

idht(v) Returns the inverse Hartley transform of the vector v.

Arguments:

v is a vector or matrix of real-valued data.


Sine and Cosine Transforms

costr(v) Returns the cosine transform of the vector v.

icostr(v) Returns the inverse cosine transform of the vector v.

isintr(v) Returns the inverse sine transform of the vector v.

sintr(v) Returns the sine transform of the vector v.

Arguments:

v is a vector or matrix containing an even number of real-valued data points.


Walsh Transform

walsh(n, k) Returns the kth Walsh function of order n.

Arguments:

n is an integer, the order of the walsh function (implying 2n data points). 0 [image] n [image] 12.

k is an integer, the index of the transformed value. 0 < k < 2n - 1.


Hilbert Transform

hilbert(v) Returns the Hilbert transform of the vector v.

Arguments:

v is a vector or matrix of real-valued data.

Note:

  • Returns a vector for which the negative frequency components exactly cancel those of the input v.

  • Hilbert-transformed analytic signals are useful for avoiding aliasing.


Two-Dimensional Convolution

twodconvol(A, B) Returns the two-dimensional convolution of the arrays A and B.

Arguments:

A and B are two-dimensional real- or complex-valued vectors or matrices.


Short-time Fourier Transform

stft(v, [n], [s], [w]) Returns a matrix containing the short time Fourier transform of a signal v; computes n frequencies, every s samples, and tapers each block with window (or window type) w.

Arguments:

v is a vector of complex-valued data.

n (optional) is an integer, the number of transform frequencies. If n is omitted, it is 64.

s (optional) is an integer, the number of samples to skip between successive computations. If s is omitted, it is n/2.

w (optional) is an integer representing a windowing function. A rectangular window is used if w is omitted. The following table shows values for w and the windows they correspond to:

Value of w | Window
1 | rectangular
2 | tapered rectangular
3 | triangular
4 | Hanning
5 | Hamming
6 | Blackman

Alternatively, w is a vector containing the coefficients of an FIR filter whose length is not longer than n.


Time-Frequency Representations and Local Autocorrelation

timecorr(v, t, l, s, [d]) Returns a matrix containing the samples of a time-depemdent autocorrelation function for a signal v, type t, l number of lags, step size s, and an optional scalar or matrix argument d.

timefreq(v, t, f, s, [d]) Returns a matrix containing the samples of a time-depemdent autocorrelation function for a signal v, type t, f number of frequencies, step size s, and an optional scalar or matrix argument d.

Arguments:

x is a vector of real-valued data.

t is a string containing the name of the desired representation (optional for the custom type).

Value of t | Representation
"wigner" | Wigner
"cone" | cone
"bornjordan" | Born-Jordan
"marghill" | Margenau-Hill
"choiwill" | Choi-Williams
"custom" | custom kernel in the time-lag plane

f is an integer, the number of lags (for timecorr) or number of frequencies (for timefreq) to be computed.

s is the step size, an integer giving the number of samples to skip between successive computations.

d (optional), positive dampening factor for the Choi-Williams distribution. Ignored for other representations. If omitted, d is 1.

When t is "custom", only v, s, and the following argument are required:

r, a matrix of real numbers giving the time-lag kernel.


Discrete Wavelet Transform

dwavelet(v) Returns a discrete wavelet transform of the vector v.

idwavelet(v) Returns the inverse of the discrete wavelet transform carried out by the dwavelet function.

Arguments:

v is a real-valued data array of length 2n where n [image] 4.


Getting information on a WAV file

GETWAVEINFO(file) Returns a vector containing the format information of a WAV file:

  • The number of channels

  • The sample rate
  • The number of bits per sample (or resolution)
  • The average number of bytes per second that an audio player device would have to process to play the audio in real time.

Arguments:

file is a string. Type " followed by the name of the file and " again.

Note:

  • file must be a pulse code modulated (PCM) Microsoft WAV file.


Reading and Writing WAV files

READWAV(file) Returns the audio data contained in a WAV file. When a matrix is returned, successive columns represent separate channels of data.

WRITEWAV(file, s, b) Writes the data contained in an array to a Microsoft WAV file using the sample rate s and bit resolution b.

Arguments:

file is a string. Type " followed by the filename and then " again.

s is a real number.

b is an integer between 1 and 16.

Example:

Note:

  • file must be a pulse code modulated (PCM) Microsoft WAV file.

  • If b is between 1 and 8, the data is written to the file as unsigned byte data. The limits on unsigned byte data are 0-256.

  • If b is between 9 and 16, word data (two bytes) is written to the file. The limits on word data are -32768 - +32767.


Welcome

The Help window for this Extension Pack has three tabs for accessing information:

  • The Contents tab gives you access to a Table of Contents which is useful when you need an overview of topics available and a guide through them.

  • The Index tab directs you to specific topics you request. Use the Index if you know the topic you are looking for.

  • The Search tab searches the entire help system for a word or phrase you request. Full-text searching is useful when you are looking for a certain word or phrase, rather than a topic.

When you double-click on a topic, it displays in the right-hand side of the window.